package org.example.shardingjdbc.controller;

import org.example.shardingjdbc.entity.User;
import org.example.shardingjdbc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.sql.DataSource;


@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private DataSource dataSource;

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public void add(@RequestBody User user) {
        userService.save(user);
    }

    @GetMapping("/query/{id}")
    public void findById(@PathVariable("id") int userId) {
        User user = userService.getById(userId);
        System.out.println(user);
    }
}
